/**
 * 单位行业树
 * @type {Object}
 */
var businessType = new Object();

//初始化
businessType.init = function () {
    businessType.initTree();
}

businessType.tree_options = {
    id: 'tree_business',
    url: appPath + '/super/business/companyBusiness_tree',
    setting: {
        check: {
            enable: true,
            chkStyle:"radio",
            radioType :  "all"
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        view: {
            dblClickExpand: false,
            fontCss: getFontCss
        },
        callback: {
            onCheck: function (e,treeId, treeNode) {
                var nodes = businessType.business_zTree.getCheckedNodes(true);
                var data = [],names = [];
                for(var i = 0; i < nodes.length; i++){
                    var n = nodes[i];
                    if(n.pId == null){
                        data = [];
                        data.push(n.id);
                        if(nodes.length > 1){
                            recursion.cancelNode(businessType.business_zTree, n);
                        }
                        return;
                    }
                    names.push(n.name);
                    data.push(n.id);
                }
                //解析参数
                $("#businessId").val(data).trigger("change");;
                $("#select-input").val(names).trigger("change");
                // $("#company_business").val(names);
               // $("#tree_business>li>span.chk").hide();// 隐藏root节点checkbox
            }
        }
    }
};

//初始化树
businessType.initTree = function(){
    $.ajax({
        url: businessType.tree_options.url,
        async: false,
        type: 'post',
        data: {},
        success: function(data){
            businessType.tree_options.zNodes = eval(data.result);
            // 加载树
            businessType.business_zTree = $.fn.zTree.init($("#tree_business"), businessType.tree_options.setting, businessType.tree_options.zNodes);
            $("#tree_business>li>span.chk").hide();
            //$("#tree_business>li>span.chk").setChkDisabled();// 隐藏root节点checkbox
        }
    });
};


//搜索高亮
function getFontCss(treeId, treeNode){
    return (!!treeNode.highlight)?{'color': "#A60000", 'font-weight':"bold"}:{'color': "#333", 'font-weight':"normal"};
}